home *** CD-ROM | disk | FTP | other *** search
- <!--- This example shows the interaction of CFIF, CFELSE,
- and CFELSEIF --->
-
- <!--- first, perform a query to get some data --->
- <CFQUERY NAME="getCenters" DATASOURCE="cfsnippets">
- SELECT Center_ID, Name, Address1, Address2,
- City, State, Country, PostalCode, Phone, Contact
- FROM Centers
- ORDER by City, State, Name
- </CFQUERY>
-
- <HTML>
- <HEAD>
- <TITLE>CFIF Example</TITLE>
- </HEAD>
-
- <BASEFONT FACE="Arial, Helvetica" SIZE=2>
- <BODY bgcolor="#FFFFD5">
-
- <H3>CFIF Example</H3>
-
- <P>CFIF gives us the ability to perform conditional logic
- based on a condition or set of conditions.
- <P>For example, we can output the list of Centers from the
- snippets datasource by group and only display them <B>IF</B>
- City = San Diego.
- <hr>
- <!--- use CFIF to test a condition when outputting
- a query --->
- <P>The following are centers in San Diego:
-
- <CFOUTPUT QUERY="getCenters" >
- <CFIF #Trim(City)# is "San Diego">
- <BR><B>Name/Address:</B>#Name#, #Address1#, #City#, #State#
- <BR><B>Contact:</B> #Contact#<BR>
- </CFIF>
- </CFOUTPUT>
- <HR>
- <P>If we would like more than one condition to be the case,
- we can ask for a list of the centers in San Diego <B>OR</B>
- Santa Ana. If the center does not follow this condition, we
- can use CFELSE to show only the names and cities of the
- other centers.
- <P>Notice how a nested CFIF is used to specify
- the location of the featured site (Santa Ana or San Diego).
- <!--- use CFIF to specify a conditional choice for multiple
- options; also note the nested CFIF --->
-
- <P>Complete information is shown for centers in San Diego
- or Santa Ana. All other centers are listed in italics:
-
- <CFOUTPUT QUERY="getCenters">
- <CFIF Trim(City) is "San Diego" OR Trim(City) is "Santa Ana">
- <H4>Featured Center in <CFIF Trim(City) is "San Diego">San Diego<CFELSE>Santa Ana</CFIF></H4>
- <B>Name/Address:</B>#Name#, #Address1#, #City#, #State#
- <BR><B>Contact:</B> #Contact#<BR>
- <CFELSE>
- <BR><I>#Name#, #City#</I>
- </CFIF>
- </CFOUTPUT>
- <HR>
- <P>Finally, we can use CFELSEIF to cycle through a number
- of conditions and produce varying output. Note that you
- can use CFCASE and CFSWITCH for a more elegant representation
- of this behavior.
-
- <P>
- <!--- use CFIF in conjunction with CFELSEIF to specify
- more than one branch in a conditional situation --->
- <CFOUTPUT QUERY="getCenters">
- <CFIF Trim(City) is "San Diego" OR Trim(City) is "Santa Ana">
- <BR><I>#Name#, #City#</I> (this one is in <CFIF Trim(City) is "San Diego">San Diego<CFELSE>Santa Ana</CFIF>)
- <CFELSEIF Trim(City) is "San Francisco">
- <BR><I>#Name#, #City#</I> (this one is in San Francisco)
- <CFELSEIF Trim(City) is "Suisun">
- <BR><I>#Name#, #City#</I> (this one is in Suisun)
- <CFELSE>
- <BR><I>#Name#</I> <B>Not in a city we track</B>
- </CFIF>
- </CFOUTPUT>
-
- </BODY>
- </HTML>
-